/**
 * Copyright:Copyright(c)2014-2017
 * Company:厦门市易致达物联网科技有限公司
 *
 * @version 1.0
 */
package shop.controller.front.activitypicture;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import shop.core.FrontBaseController;
import shop.core.Services;
import shop.core.common.bean.JSONResult;
import shop.core.common.dao.page.PagerModel;
import shop.services.front.activity.bean.Activity;
import shop.services.front.activityjoin.ActivityjoinService;
import shop.services.front.activityjoin.bean.Activityjoin;
import shop.services.front.activitypicture.ActivitypictureService;
import shop.services.front.activitypicture.bean.Activitypicture;
import shop.services.manage.system.bean.User;
import shop.services.manage.system.impl.UserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @类名称：ActivitypictureController
 * @创建人：Wzl
 * @创建时间：2018-01-03 下午16:23:34
 * @版本号：1.0
 * @描述：
 */
@Controller
@RequestMapping("/front/activitypicture/")
public class ActivitypictureController extends FrontBaseController<Activitypicture> {
    private final  static  String ACTIVITYPICTURE_ISJOIN_YES="y";
    private final  static  String ACTIVITYPICTURE_ISJOIN_NO="n";
    private final  static  String UPLOAD_ADDRESS_FRONT="front";
    private final  static  String UPLOAD_ADDRESS_MANAGE="manage";
    @Resource
    private ActivitypictureService activitypictureService;
    @Resource
    private ActivityjoinService activityjoinService;
    @Resource
    private UserService userService;

    @Override
    public Services<Activitypicture> getService() {
        return activitypictureService;
    }

    /**
     * 查询活动照片
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("selectActivityPicture")
    @ResponseBody
    public JSONResult selectActivityPicture(Activitypicture activitypicture) {
        List<Activitypicture> activitypictureList = activitypictureService.selectActivityPicture(activitypicture);
        JSONResult jsonResult = new JSONResult();
        jsonResult.setData(activitypictureList);
        return jsonResult;
    }

    /**
     * 上传活动照片
     *
     * @return jsonResult
     * @throws Exception
     */
    @RequestMapping(value = "insertActivityPicture", method = RequestMethod.POST)
    @ResponseBody
    public JSONResult insertActivityPicture(HttpSession session, Activitypicture activitypicture) {
        JSONResult jsonResult = new JSONResult();
        User user = (User) session.getAttribute("userInfo");
        activitypicture.setUserID(user.getId());
        Activityjoin activityjoin = new Activityjoin();
        activityjoin.setUserID(user.getId());
        activityjoin.setActivityID(activitypicture.getActivityID());
        activityjoin = activityjoinService.selectOne(activityjoin);
        if (activityjoin == null){
            activitypicture.setIsJoin(ACTIVITYPICTURE_ISJOIN_NO);
        }else{
            activitypicture.setIsJoin(ACTIVITYPICTURE_ISJOIN_YES);
        }
        activitypicture.setUploadAddress(UPLOAD_ADDRESS_FRONT);
        activitypictureService.insert(activitypicture);
        return jsonResult;
    }

    @Override
    public JSONResult deleteJson(HttpServletRequest request, Activitypicture activitypicture) throws Exception {
        return null;
    }
}
